<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="处理单位：">
          <el-select v-model="listPram.departmentId" placeholder="请选择">
            <el-option
                v-for="item in hearList1"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分类：">
          <el-select v-model="listPram.type" placeholder="分类" clearable style="width: 100%">
            <el-option :label="item.name" :value="item.id" v-for="item in typeList" :key="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
<!--        <el-form-item class="el-form-item-align-right">-->
<!--          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="openEdit()" v-has-permi="['admin:salvation:save']">添加</el-button>-->
<!--        </el-form-item>-->
      </el-form>
      <el-table :data="listData.list" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" width="120" ></el-table-column>
        <el-table-column label="状态" prop="allocationStatus" min-width="50" >
          <template slot-scope="scope">
            <div style="color:dodgerblue;" v-if="scope.row.statusText=='已分配'">{{scope.row.statusText}}</div>
            <div style="color:yellowgreen;" v-if="scope.row.statusText=='待分配'">{{scope.row.statusText}}</div>
            <div style="color:#FF8D02;" v-if="scope.row.statusText=='已办结'">{{scope.row.statusText}}</div>
            <div style="color:dodgerblue;" v-if="scope.row.statusText=='已处理'">{{scope.row.statusText}}</div>
            <div style="color:#FF8D02;" v-if="scope.row.statusText=='待处理'">{{scope.row.statusText}}</div>
          </template>
        </el-table-column>
        <el-table-column label="处理单位" prop="realName"/>
        <el-table-column label="种类" prop="typeText" width="130"/>
        <el-table-column label="位置" prop="position" width="150"/>
        <el-table-column label="具体位置" prop="specificPosition" min-width="160"/>
        <el-table-column label="野生动物情况" prop="animalSituation" min-width="180"/>
        <el-table-column label="创建时间" prop="createTime" min-width="130"/>
        <el-table-column label="操作" min-width="180" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button icon="el-icon-set-up" type="success" size="mini" @click="setDeal2(scope.row)" v-show="scope.row.allocationStatus==1" v-has-permi="['admin:salvation:allot']">分配</el-button>
            <el-button icon="el-icon-s-cooperation" size="mini" type="primary" @click="openEdit1(scope.row.id)" v-show="scope.row.allocationStatus==2" v-has-permi="['admin:salvation:dispose']">处理</el-button>
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id)" v-has-permi="['admin:salvation:detail']">详情</el-button>
            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)" v-has-permi="['admin:salvation:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="[20,40,60,80,100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="editDialog.show"
      :title="editDialog.id? '详情':'详情'"
      destroy-on-close
      :close-on-click-modal="false"
      width="1200px">
      <edit
        v-if="editDialog.show"
        :id="editDialog.id"
        @hideEditDialog="hideEditDialog"
        ref="editForm"
      />
    </el-dialog>
    <el-dialog
        :visible.sync="editDialog1.show"
        title="处理"
        destroy-on-close
        :close-on-click-modal="false"
        width="1500px">
      <edit1
          v-if="editDialog1.show"
          :id="editDialog1.id"
          @hideEditDialog="hideEditDialog1"
          ref="editForm"
      />
    </el-dialog>
    <el-dialog width="50%"  v-if="dialogVisible3" :visible.sync="dialogVisible3" title="分发" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <Edit2 ref="detail" :id="id"  :Close3="Close3"></Edit2>
      <span slot="footer" class="dialog-footer" v-if="adminUserId==1">
        <el-button type="primary" class="primary" @click="$refs.detail.distribute(id)">确 定</el-button>
      </span>
      <span slot="footer" class="dialog-footer" v-else-if="adminUserId==2 || adminUserId==3">
        <el-button type="primary" class="primary" @click="$refs.detail.distribute(id)"  :disabled="true">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit'
import {deleteRow, getAnimalTypeApi, list, updateStatus} from "@/api/salvation";
import {checkPermi} from "@/utils/permission";
import {getForm} from "@/utils/utils";
import {list1} from "@/api/disaster";
import edit1 from "@/views/salvation/edit1.vue";
import Edit2 from "@/views/salvation/edit2.vue";
import * as disasterApi from "@/api/disaster";
export default {
  components: { edit,edit1,Edit2 },
  data() {
    return {
      adminUserId:0,
      listData: { list: [],count:3 },
      listPram: {
        departmentId:null,
        keyword: '',
        page: 1,
        limit: 20,
        type:null,
        // dispose:[]
      },
      id:0,
      dialogVisible3: false,//分配dialog
      dialogVisible4: false,//处理dialog
      typeList:[],
      hearList1:[],
      editDialog:{
        show:false,
        id:null
      },
      editDialog1:{
        show:false,
        id:null
      },
      tableLoading:false,
    }
  },
  mounted() {
    this.getList()
    // this.getList1()
    this.getAnimalType()
    this.selectReviewRoom()
  },
  methods: {
    getAnimalType(){
      getAnimalTypeApi().then(res=>{
        this.typeList = res
      })
    },
    selectReviewRoom() {
      this.hearListLoading = true
      disasterApi.list1().then(res => {
        this.hearList1 = res.list
      }).finally(()=>{
        this.hearListLoading = false
      })
    },
    checkPermi,
    getList(){
      this.tableLoading=true
      list(this.listPram).then(res=>{
        this.listData=res;
      }).finally(()=>{})
      this.tableLoading=false;
    },
    Close3() {
      this.dialogVisible3 = false
      this.getList()
    },
    setDeal2(row){
      this.dialogVisible3 = true
      this.id = row.id;
      this.adminUserId = row.allocationStatus
    },
    openEdit(id=null){
      this.editDialog.id=id;
      this.editDialog.show=true
    },
    openEdit1(id=null){
      this.editDialog1.id=id;
      this.editDialog1.show=true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading=this.$loading({text:'删除中',background:'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(()=>{
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    hideEditDialog1() {
      this.editDialog1.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    handleStatusChange(status,id){
      const loading=this.$loading({text:'更新中',background:'rgba(255,255,255,.5)'})
      updateStatus(id,status).then(()=>{
        this.$message.success('更新状态成功')
        this.getList()
      }).finally(()=>{
        loading.close()
      })
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.listPram.type = null;
      this.listPram.departmentId = null
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
